package user_partner_reward

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPartnerRewardsInsertLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 添加
func NewUserPartnerRewardsInsertLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPartnerRewardsInsertLogic {
	return &UserPartnerRewardsInsertLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPartnerRewardsInsertLogic) UserPartnerRewardsInsert(req *types.UserPartnerInsertRequest) (resp *types.UserPartnerInsertResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.User.UserPartnerRewardsInsert(l.ctx, &rpc.UserPartnerInsertRequest{
		UserId:         req.UserId,
		InviteCode:     req.InviteCode,
		SubordinateId:  req.SubordinateId,
		RechargeAmount: req.RechargeAmount,
		RewardAmount:   req.RewardAmount,
		RechargeTime:   req.RechargeTime,
		RegisterTime:   req.RegisterTime,
	})

	if err != nil {
		return &types.UserPartnerInsertResponse{
			IsInsert: false,
		}, err
	}
	return &types.UserPartnerInsertResponse{
		IsInsert: true,
	}, err
}
